package com.openjaw.lsy.agent.core.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FileUtils {
    public static HashMap<String, Map<String, List<String>>> hashMap = new HashMap<>();
    private static String businessType;

    public static void getFileList(String path, String type) {
        File file = null;
        String key = null;
        if (type.equals("Client")) {
            businessType = type;
            hashMap.put("Client", new HashMap<String, List<String>>());
            path = path + "\\Client";
        } else if (type.equals("Supplier")) {
            businessType = type;
            hashMap.put("Supplier", new HashMap<String, List<String>>());
            path = path + "\\Supplier";
        } else {
            key = type;
        }
        file = new File(path);
        File[] fileList = file.listFiles();

        for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isFile()) {
                if (key != null) {
                    hashMap.get(businessType).get(key).add(fileList[i].getName());
                }

            }

            if (fileList[i].isDirectory()) {
                String directoryName = fileList[i].getName();
                String nextPath = path + "\\" + directoryName + "\\services";
                if (!new File(nextPath).isDirectory()) {
                    nextPath = path + "\\" + directoryName;
                }
                hashMap.get(type).put(directoryName, new ArrayList<String>());
                getFileList(nextPath, directoryName);

            }
        }
    }

    public static void main(String args[]) {
        getFileList("C:\\ExternalWebs\\TravelSky-Hainan\\xDistHome\\config\\openjaw", "Supplier");
        System.out.println(hashMap.toString());
    }
}
